﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataModel;

namespace Web
{
    public partial class productEdit : System.Web.UI.Page
    {
        daProduct d = new daProduct();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                dsProduct ds = new dsProduct();

                string id = Request.QueryString["id"];

                ds.Clear();
                ds.Merge(d.GetProductBy(id));

                TextBox1.Text = ds.Tables[0].Rows[0]["id"].ToString();
                TextBox1.ReadOnly = true;
                TextBox2.Text = ds.Tables[0].Rows[0]["productname"].ToString();
                TextBox3.Text = ds.Tables[0].Rows[0]["productdesc"].ToString();
                this.ViewState.Add("data", ds);
            }
        }

        protected void btnupdate_Click(object sender, EventArgs e)
        {
            dsProduct ds = (dsProduct)this.ViewState["data"];
            ds.Tables[0].BeginInit();
            ds.Tables[0].Rows[0]["productname"] = TextBox2.Text;
            ds.Tables[0].Rows[0]["productdesc"] = TextBox3.Text;
            ds.Tables[0].EndInit();

            if (ds.HasChanges())
            {
                Response.Write("changes" + "\n");
            }

            d.UpdateProduct(ds);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            dsProduct ds = (dsProduct)this.ViewState["data"];
            if (ds.HasChanges())
            {
                Response.Write("changes" + "\n");
            }
            d.UpdateProduct(ds);
        }
    }
}